package com.lijianlove.message.confirm.service;

import com.lijianlove.message.common.enums.MsgStatusEnum;
import com.lijianlove.message.common.model.Message;
import com.lijianlove.message.dal.MessageStoreService;
import com.lijianlove.message.service.api.IMessageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.util.List;

/**
 * @author lijian
 * @date 2019/5/30 下午4:50
 */
@Slf4j
@Service
public class ConfirmService {

    @Autowired
    private MessageStoreService messageStoreService;

    @Autowired
    private IMessageService messageService;

    public void verify() {
        List<Message> messages = messageStoreService.listByStatus(MsgStatusEnum.INIT);
        if (!ObjectUtils.isEmpty(messages)) {
            messages.forEach(item -> {
                log.info("verify msg {}", item);
                // 如果验证成功
                log.info("resend msg {}", item);
                messageService.confirmAndSendMessage(item.getId());

            });
        }
    }
}
